package com.fg.pro.ai.controller;



import com.alibaba.cloud.ai.dashscope.image.DashScopeImageOptions;
import com.fg.pro.ai.service.AiImageService;
import com.fg.pro.ai.utils.AiByAlibabaUtils;
import com.fg.pro.model.config.ValidationGroups;
import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.model.sys.entity.SysMenu;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * ai图片(AiImage)表控制层
 *
 * @author makejava
 * @since 2025-09-12 15:36:54
 */
@RestController
@RequestMapping("aiImage")
public class AiImageController {
    /**
     * 服务对象
     */
    @Autowired
    private AiImageService aiImageService;

    @Operation(summary = "获取ai图片模型列表",description = "")
    @GetMapping("/getAiModel")
    public ResponseResult imgByBlock(){
        List<AiByAlibabaUtils.AiMode> modeList = AiByAlibabaUtils.getAiImageModeList();
        return ResponseResult.okResult(modeList);
    }

    @Operation(summary = "创建ai图片(阿里百炼)(阻塞)",description = "参数ai图片描述")
    @PutMapping("/save")
    public ResponseResult save(@RequestParam (required = false) String imgDes,@RequestParam(required = true)String modelCode) throws InterruptedException {
        boolean save = aiImageService.saveByAi(imgDes,modelCode);
        return ResponseResult.okResult(save?"请等待":"添加失败");
    }

    @Operation(summary = "获取ai图片分页信息",description = "参数ai图片描述")
    @GetMapping("/getPage")
    public ResponseResult getPage(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false,defaultValue = "10") Integer pageSize,
                                  @RequestParam(required = false)@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                  @RequestParam(required = false)@DateTimeFormat(pattern = "yyyy-MM-dd") Date end,
                                  @RequestParam(required = false) String imgDes){
        PageInfo pageInfo = aiImageService.getPage(pageNum,pageSize,start,end,imgDes);
        return ResponseResult.okResult(pageInfo);
    }

}

